{% extends "member/layout.html" %}

{% block title %}项目结项审批 - {{ project.name }}{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <!-- 页面标题 -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="fw-bold text-primary">
                <i class="fas fa-file-signature me-2"></i>项目结项审批
            </h2>
            <a href="{{ url_for('member.jira.project_detail', project_id=project.id) }}"
               class="btn btn-outline-secondary">
                <i class="fas fa-arrow-left me-1"></i>返回项目
            </a>
        </div>

        <!-- 结项审批卡片 -->
        <div class="card dashboard-card border-0">
            <div class="card-body">
                <!-- 项目信息 -->
                <div class="mb-4">
                    <h5 class="fw-bold mb-3">{{ project.name }}</h5>
                    <div class="d-flex align-items-center mb-3">
                        <div class="bg-primary bg-opacity-10 p-2 rounded-circle me-3">
                            <i class="fas fa-folder text-primary"></i>
                        </div>
                        <div>
                            <p class="text-muted mb-0">{{ project.description }}</p>
                        </div>
                    </div>
                </div>

                <!-- 结项申请信息 -->
                <div class="mb-4 border-bottom pb-4">
                    <h6 class="fw-bold mb-3">结项申请信息</h6>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <p class="text-muted small mb-1">申请人</p>
                                <p class="fw-medium">{{ project.owner.name }}</p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <p class="text-muted small mb-1">申请时间</p>
                                <p class="fw-medium">
                                    {{ project.closure_requested_at.strftime('%Y-%m-%d %H:%M') if project.closure_requested_at else '未设置' }}
                                </p>
                            </div>
                        </div>
                    </div>
                    {% if project.closure_notes %}
                    <div class="bg-light rounded p-3">
                        <p class="text-muted small mb-1">申请说明</p>
                        <p class="mb-0">{{ project.closure_notes }}</p>
                    </div>
                    {% endif %}
                </div>

                <!-- 审批操作 -->
                {% if approval.status == 'pending' %}
                <div class="mb-4">
                    <h6 class="fw-bold mb-3">审批操作</h6>
                    <form method="post" action="{{ url_for('member.closure.review', approval_id=approval.id) }}">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <div class="mb-4">
                            <label for="notes" class="form-label fw-medium">审批意见</label>
                            <textarea class="form-control" id="notes" name="notes" rows="4"
                                      placeholder="请输入审批意见..." required></textarea>
                        </div>
                        <div class="d-flex justify-content-start gap-3">
                            <button type="submit" name="action" value="reject"
                                    class="btn btn-outline-danger px-4 py-2">
                                <i class="fas fa-times me-2"></i>拒绝结项
                            </button>
                            <button type="submit" name="action" value="approve"
                                    class="btn btn-success px-4 py-2">
                                <i class="fas fa-check me-2"></i>批准结项
                            </button>
                        </div>
                    </form>
                </div>
                {% endif %}

                <!-- 审批历史 -->
                <div>
                    <h6 class="fw-bold mb-3">审批历史</h6>
                    {% if history %}
                    <div class="list-group">
                        {% for record in history %}
                        <div class="list-group-item">
                            <div class="d-flex justify-content-between">
                                <div>
                                    <p class="fw-bold mb-1">
                                        {{ record.reviewer.name if record.reviewer else '系统' }}
                                        <span class="badge ms-2 bg-{{ 'success' if record.status == 'approved' else 'danger' if record.status == 'rejected' else 'warning' }}">
                                            {{ record.status_label }}
                                        </span>
                                    </p>
                                    {% if record.review_notes %}
                                    <p class="text-muted mb-1">"{{ record.review_notes }}"</p>
                                    {% endif %}
                                </div>
                                <small class="text-muted">
                                    {{ record.reviewed_at.strftime('%Y-%m-%d %H:%M') if record.reviewed_at else '待处理' }}
                                </small>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="text-center py-4 text-muted">
                        <i class="fas fa-history me-2"></i>暂无审批历史记录
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.dashboard-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    padding: 2rem;
}

.badge {
    font-weight: 500;
}
</style>
{% endblock %}